package com.asdan.seededu.service.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import com.asdan.seededu.entity.security.InfoConfirm;
import com.asdan.seededu.entity.security.User;
import com.asdan.seededu.service.InfoConfirmService;
import com.asdan.seededu.util.DatabaseAccess;
import com.demo2do.core.utils.JsonUtils;

public class InfoConfirmServiceImpl extends UtilImpl implements InfoConfirmService{
	public InfoConfirm getInfo(int oid){
		DatabaseAccess databaseAccess = new DatabaseAccess(false);
		Connection cn = null;
		PreparedStatement pstmt=null;
		ResultSet rs = null;
		InfoConfirm info = null ;
		String sql = "select * from orders where oid=? ";
		System.out.println(sql);
		
		try{
			cn = databaseAccess.getConn();
			pstmt = cn.prepareStatement(sql);
			pstmt.setInt(1, oid) ;
			rs = pstmt.executeQuery();
			while(rs.next()){
				info= new InfoConfirm();
				System.out.println(rs.getString("information"));
				info.setUser(JsonUtils.parse(rs.getString("information"), User.class)) ;
				info.setIfHotel(rs.getInt("price"));
				
			}
		}catch(Exception e){
			e.printStackTrace();
			System.out.println(e.getMessage());
		}finally{                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
			try{
				pstmt.close();
				cn.close();
				databaseAccess.close() ;
			}catch(Exception ex){
					pstmt = null ;
					cn = null ;
			}
		}
		return info ;
	}
	
	
	//获取获奖等等信息
		public InfoConfirm getOtherinfo(int uid,int spid){
			DatabaseAccess databaseAccess = new DatabaseAccess(false);
			Connection cn = null;
			PreparedStatement pstmt=null;
			ResultSet rs = null;
			InfoConfirm otherinfo = null ;
			String sql = "select * from userdata where uid=? and spid=? ";//从userdata获取获奖等信息
			System.out.println(sql);

			try{
				cn = databaseAccess.getConn();
				pstmt = cn.prepareStatement(sql);
				pstmt.setInt(1, uid) ;
				pstmt.setInt(2, spid) ;
				rs = pstmt.executeQuery();
				while(rs.next()){
					otherinfo= new InfoConfirm();
					otherinfo.setUser(JsonUtils.parse(rs.getString("data"), User.class)) ;	
				}
				}catch(Exception e){
					e.printStackTrace();
					System.out.println(e.getMessage());
				}finally{                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
					try{
						pstmt.close();
						cn.close();
						databaseAccess.close() ;
					}catch(Exception ex){
							pstmt = null ;
							cn = null ;
					}
				}
				return otherinfo ;
			}	
}
